package CharacterDevelop;

import java.util.Scanner;

/**
 * ClassName:StringTest004
 * Package:CharacterDevelop
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/16-0:04
 * @Version:v1.0
 */
public class StringTest004 {
    /*
     * 已知正确的用户名和密码,请用程序实现模拟用户登录
     * 一共三次机会,登陆之后,给出相应的提示
     * */
    public static void main(String[] args) {
        //1.定义两个变量记录正确的用户名和密码
        String rightUsername = "ZhangSan";
        String rightPassword = "123456";


        //2.键盘录入用户名和密码
        for (int i = 0; i < 3; i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入用户名:");
            String username = sc.next();
            System.out.println("请输入密码  :");
            String password = sc.next();

            //3.比较
            if (username.equals(rightUsername) && password.equals(rightPassword)) {
                System.out.println("用户登录成功");
                System.out.println("------------------------------------");
                break;
            } else {
                if (i == 2) {
                    //最后一次机会也会输入错误,此时要提示账号被锁定
                    System.out.println("账号被锁定,请联系客服：1008611");
                } else {
                    System.out.println("用户登录失败,用户名或密码错误,您还剩下" + (2 - i) + "次机会");
                    System.out.println("------------------------------------");
                }
            }
        }


    }
}
